//WebProtect.cpp : Defines the entry point for the BHO DLL application.
//Author: Peng Chong
//Date  : June/05/2009
//

#include "stdafx.h"
#include "resource.h"
#include <initguid.h>

#include "webProtect_h.h"
#include "webProtect_i.c"
#include "webProtectClass.h"
#include "util.h"


#ifdef _MANAGED
#pragma managed(push, off)
#endif

CComModule _Module;

BEGIN_OBJECT_MAP(ObjectMap)
OBJECT_ENTRY(CLSID_WebProtectClass,CWebProtectClass)
END_OBJECT_MAP()

///////////////////////////////////////////////
//DLL entry
extern "C"
BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	if ( ul_reason_for_call == DLL_PROCESS_ATTACH)
    {
		// Check to see if we've been called by Windows Explorer rather than
		// Internet Explorer, and return fail if called by Windows Explorer
		
		TCHAR szFilename[MAX_PATH];
		memset( szFilename, '\0', MAX_PATH*sizeof(TCHAR) );
		GetModuleFileName(NULL, szFilename, MAX_PATH);

#ifdef WEB_DEBUG
		dbgPrint(L"[%s]The module file name is %s",APP_NAME,szFilename );
#endif
		_tcslwr_s(szFilename,MAX_PATH);

		if (_tcsstr(szFilename, _T("explorer.exe")) != NULL)
		{
			return FALSE;
		}
			
		/* ANSI method
		char szFile[MAX_PATH];
		memset( szFile,'\0',MAX_PATH );
		GetModuleFileNameA( NULL,szFile,MAX_PATH );
		_strlwr_s( szFile, MAX_PATH );
		if( strstr( szFile,"explorer.exe" ) != NULL )
		{
			return FALSE;
		}
		*/
		
        _Module.Init(ObjectMap, hModule, &LIBID_WebProtectLib);

		// For performance reasons, we don't want to be called on thread events
        DisableThreadLibraryCalls(hModule);
    }
    else if( ul_reason_for_call == DLL_PROCESS_DETACH)
	{
		_Module.Term();
	}

    return TRUE;
}

////////////////////////////////////////////////
// Unload entry
STDAPI DllCanUnloadNow()
{
	return ( (_Module.GetLockCount() == 0) ? S_OK : S_FALSE );
}

////////////////////////////////////////////////
// Register server entry
STDAPI DllRegisterServer()
{
	return _Module.RegisterServer(TRUE);
}

////////////////////////////////////////////////
// UnRegister server entry
STDAPI DllUnregisterServer()
{
	return _Module.UnregisterServer(TRUE);
}

/////////////////////////////////////////////////////////////////////////////
// Returns a class factory to create an object of the requested type
STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
{
    return _Module.GetClassObject(rclsid, riid, ppv);
}

#ifdef _MANAGED
#pragma managed(pop)
#endif

